from selenium import webdriver
from selenium.webdriver.common.by import By
import time


class OperationBrowser:
    def __init__(self):
        self.driver = webdriver.Chrome()
        self.driver.get('https://www.baidu.com')

    def id(self):
        kw = self.driver.find_element(By.ID,'kw')
        print(kw.get_attribute('outerHTML'))

        su= self.driver.find_element(By.ID,'su')
        print(su.get_attribute('outerHTML'))

    def class_name(self):
        kw = self.driver.find_element(By.CLASS_NAME,'s_ipt')
        print(kw.get_attribute('outerHTML'))

    def link_text(self):
        news = self.driver.find_element((By.LINK_TEXT,'新闻'))
        print(news.get_attribute('outerHTML'))

    def partial_link_text(self):
        hao123 = self.driver.find_element(By.PARTIAL_LINK_TEXT,'hao')
        print(hao123.get_attribute('outerHTML'))

    def name(self):
        ie = self.driver.find_element(By.NAME,'ie')
        print(ie.get_attribute('outerHTML'))

    def tag_name(self):
        ipt = self.driver.find_element(By.TAG_NAME,'input')
        print(ipt.get_attribute('outerHTML'))

        inputs = self.driver.find_elements(By.TAG_NAME,'input')
        print(inputs)
        print(len(inputs))
        for i in inputs:
            print(i.get_attribute('outerHTML'))






    def quit(self,seconds):
        time.sleep(seconds)
        self.driver.quit()


if __name__ == '__main__':
    oper = OperationBrowser()
    oper.id()
    oper.quit()
